home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / PLOT.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  17KB  |  556 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992, 1993  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*            GNUPLOT shell          */
  14. /*             dialog box            */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <string.h>
  26. #include <io.h>
  27. #include "globals.h"
  28. #include "defines.h"
  29. #include "strtbl.h"
  30. #include "gwsim.h"
  31. #include "simgvar.h"
  32. #include "basic.h"
  33. #include "gep2.h"
  34.  
  35. void AddXYZLst( HWND hControl, LPSTR text );
  36. void plot_text( LPSTR Buff );
  37. void label_dyn( int idx, LPSTR str );
  38. void label_dat( int idx, LPSTR str );
  39.  
  40. #pragma alloc_text( CODE16, AddXYZLst, Plot, plot_text, label_dyn, label_dat, GnuPlot )
  41.  
  42.  
  43. /* function to add column titles on the X, Y and Z lists    */
  44.  
  45. void AddXYZLst( HWND hControl, LPSTR text )
  46. {
  47.  int i;
  48.  WORD ElWidth;
  49.  HANDLE hDC;
  50.  
  51.  hDC = GetDC( hControl );
  52.  ElWidth = 5 + LOWORD( GetTextExtent( hDC, text, _fstrlen(text) ) );
  53.  SetTextJustification( hDC, 0, 0 );
  54.  ReleaseDC( hControl, hDC );
  55.  if( ElWidth > lbWidth )
  56.  {
  57.   lbWidth = ElWidth;
  58.   SendMessage( hControl, LB_SETHORIZONTALEXTENT, lbWidth, 0 );
  59.  }
  60.  SendMessage( hControl, LB_INSERTSTRING, -1, (DWORD) text );
  61. }
  62.  
  63.  
  64.  
  65. /* Function for the Plot... dialog box    */
  66.  
  67. int FAR PASCAL Plot(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  68. {
  69.  static HWND hX, hY, hZ, hZlog, hZtext, hDyn, hSs, hCont, hHidd;
  70.  static int file, type;
  71.  int  i,j;
  72.  char auxstr[NAME_L+5];
  73.  
  74.  switch(Message)
  75.  {
  76.   case WM_INITDIALOG:
  77.    /* save file and type                            */
  78.    file = plot.file;
  79.    type = plot.type;
  80.  
  81.    /* check if any data can be available            */
  82.    if( ( (totsel==0) ) && (!options.dyn) )
  83.     SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  84.  
  85.    /* get handles to controls                        */
  86.    hX     = GetDlgItem( hDlg, IDC_X );
  87.    hY     = GetDlgItem( hDlg, IDC_Y );
  88.    hZ     = GetDlgItem( hDlg, IDC_Z );
  89.    hZlog  = GetDlgItem( hDlg, IDRB_3E );
  90.    hZtext = GetDlgItem( hDlg, IDSTAT_5 );
  91.    hDyn   = GetDlgItem( hDlg, IDC_DYNAMICS );
  92.    hSs    = GetDlgItem( hDlg, IDC_SS );
  93.    hCont  = GetDlgItem( hDlg, IDRB_5E );
  94.    hHidd  = GetDlgItem( hDlg, IDRB_5I );
  95.  
  96.    /* disable Z and check boxes if type is 2D */
  97.    if( type==0 )
  98.    {
  99.     EnableWindow( hZ, FALSE );
  100.     EnableWindow( hZlog, FALSE );
  101.     EnableWindow( hZtext, FALSE );
  102.     EnableWindow( hCont, FALSE );
  103.     EnableWindow( hHidd, FALSE );
  104.    }
  105.  
  106.    /* check the appropriate file radio button        */
  107.    if( ! options.dyn )
  108.    {
  109.     EnableWindow( hDyn, FALSE );
  110.     file = 1;
  111.    }
  112.    if( totsel==0 )
  113.    {
  114.     EnableWindow( hSs, FALSE );
  115.     file = 0;
  116.    }
  117.  
  118.    if( file==0 )
  119.     SendMessage( hDyn, BM_SETCHECK, (WORD) 1, 0 );
  120.    else
  121.     SendMessage( hSs, BM_SETCHECK, (WORD) 1, 0 );
  122.  
  123.  
  124.    /* check the appropriate type radio button        */
  125.    SendDlgItemMessage( hDlg, IDRB_0E+plot.type, BM_SETCHECK, (WORD) 1, 0 );
  126.  
  127.    /* check boxes                                    */
  128.    SendDlgItemMessage( hDlg, IDRB_4E, BM_SETCHECK, (WORD) plot.lines, 0 );
  129.    SendDlgItemMessage( hDlg, IDRB_2E, BM_SETCHECK, (WORD) plot.logx, 0 );
  130.    SendDlgItemMessage( hDlg, IDRB_2I, BM_SETCHECK, (WORD) plot.logy, 0 );
  131.    SendDlgItemMessage( hDlg, IDRB_3E, BM_SETCHECK, (WORD) plot.logz, 0 );
  132.    SendDlgItemMessage( hDlg, IDRB_4I, BM_SETCHECK, (WORD) plot.colour, 0 );
  133.    SendDlgItemMessage( hDlg, IDRB_5E, BM_SETCHECK, (WORD) plot.contour, 0 );
  134.    SendDlgItemMessage( hDlg, IDRB_5I, BM_SETCHECK, (WORD) plot.hidden, 0 );
  135.  
  136.    /* initialize hX, hY and hZ: add all columns        */
  137.    if( file==1 )
  138.    {
  139.     if( plot.ny > totsel )
  140.      plot.ny = 0;
  141.     else
  142.      for(i=0; i<plot.ny; i++ )
  143.       if( plot.y[i] > totsel )
  144.        for( j=i; j<plot.ny; j++ )
  145.        {
  146.         plot.y[j] = plot.y[j+1];
  147.         i--;
  148.        }
  149.     for( i=0, lbWidth=0; i<totsel; i++ )
  150.      for( j=0; j<noutpel; j++ )
  151.       if( (outpel[j].idx-1) == (unsigned int) i )
  152.       {
  153.        AddElLst( hX, outpel, j, FALSE );
  154.        AddElLst( hY, outpel, j, FALSE );
  155.        AddElLst( hZ, outpel, j, FALSE );
  156.       }
  157.    }
  158.    else
  159.    {
  160.     lbWidth=0;
  161.     AddXYZLst( hX, (LPSTR) "time" );
  162.     AddXYZLst( hY, (LPSTR) "time" );
  163.     AddXYZLst( hZ, (LPSTR) "time" );
  164.     for( i=0; i<nmetab; i++ )
  165.     {
  166.      wsprintf( (LPSTR) auxstr, "[%s]", (LPSTR) metname[i] );
  167.      AddXYZLst( hX, (LPSTR) auxstr );
  168.      AddXYZLst( hY, (LPSTR) auxstr );
  169.      AddXYZLst( hZ, (LPSTR) auxstr );
  170.     }
  171.     for( i=0; i<nsteps; i++ )
  172.     {
  173.      wsprintf( (LPSTR) auxstr, "J(%s)", (LPSTR) stepname[i] );
  174.      AddXYZLst( hX, (LPSTR) auxstr );
  175.      AddXYZLst( hY, (LPSTR) auxstr );
  176.      AddXYZLst( hZ, (LPSTR) auxstr );
  177.     }
  178.    }
  179.  
  180.    /* highlight the current selections            */
  181.    SendMessage( hX, LB_SETCURSEL, (WORD) plot.x, 0 );
  182.    SendMessage( hZ, LB_SETCURSEL, (WORD) plot.z, 0 );
  183.    for( i=0; i<plot.ny; i++)
  184.     SendMessage( hY, LB_SELITEMRANGE, 1, MAKELONG( plot.y[i], plot.y[i] ) );
  185.  
  186.    /* cause a WM_PAINT to be sent to the window    */
  187.    InvalidateRect( hDlg, NULL, FALSE );
  188.    return TRUE;
  189.  
  190.   case WM_COMMAND:
  191.    switch(wParam)
  192.    {
  193.     case IDC_Y:
  194.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  195.      {
  196.       if( type!=0 )
  197.       {
  198.        for( i=0; i<plot.ny; i++ )
  199.         SendMessage( hY, LB_SELITEMRANGE, 0, MAKELONG( plot.y[i], plot.y[i] ) );
  200.       }
  201.       plot.ny = (int) SendMessage( hY, LB_GETSELITEMS, (WORD) 10, (DWORD) (int huge *) plot.y );
  202.      }
  203.      return TRUE;
  204.  
  205.  
  206.     case IDRB_0E:
  207.      if( SendDlgItemMessage( hDlg, IDRB_0E, BM_GETCHECK, 0, 0 ) )
  208.      {
  209.       type = 0;
  210.       SendMessage( hZ, LB_SETCURSEL, -1, 0 );
  211.       EnableWindow( hZ, FALSE );
  212.       EnableWindow( hZlog, FALSE );
  213.       EnableWindow( hZtext, FALSE );
  214.       EnableWindow( hCont, FALSE );
  215.       EnableWindow( hHidd, FALSE );
  216.       InvalidateRect( hDlg, NULL, FALSE );
  217.      }
  218.      return TRUE;
  219.  
  220.     case IDRB_0I:
  221.      if( SendDlgItemMessage( hDlg, IDRB_0I, BM_GETCHECK, 0, 0 ) )
  222.       if( type == 0 )
  223.       {
  224.        plot.ny = (int) SendMessage( hY, LB_GETSELITEMS, (WORD) 10, (DWORD) (int huge *) plot.y );
  225.        for( i=0; i<plot.ny; i++ )
  226.         SendMessage( hY, LB_SELITEMRANGE, 0, MAKELONG( plot.y[i], plot.y[i] ) );
  227.        EnableWindow( hZ, TRUE );
  228.        EnableWindow( hZlog, TRUE );
  229.        EnableWindow( hZtext, TRUE );
  230.        EnableWindow( hCont, TRUE );
  231.        EnableWindow( hHidd, TRUE );
  232.        InvalidateRect( hDlg, NULL, FALSE );
  233.       }
  234.       type = 1;
  235.      return TRUE;
  236.  
  237.     case IDC_SS:
  238.      if(  ( SendDlgItemMessage( hDlg, IDC_SS, BM_GETCHECK, 0, 0 ) )
  239.         &&
  240.           ( file==0 )
  241.        )
  242.      {
  243.       file=1;
  244.       SendMessage( hX, LB_RESETCONTENT, 0, 0 );
  245.       SendMessage( hY, LB_RESETCONTENT, 0, 0 );
  246.       SendMessage( hZ, LB_RESETCONTENT, 0, 0 );
  247.       for( i=0, lbWidth=0; i<totsel; i++ )
  248.        for( j=0; j<noutpel; j++ )
  249.         if( (outpel[j].idx-1) == (unsigned int) i )
  250.         {
  251.          AddElLst( hX, outpel, j, FALSE );
  252.          AddElLst( hY, outpel, j, FALSE );
  253.          AddElLst( hZ, outpel, j, FALSE );
  254.         }
  255.      }
  256.      return TRUE;
  257.  
  258.     case IDC_DYNAMICS:
  259.      if(  ( SendDlgItemMessage( hDlg, IDC_DYNAMICS, BM_GETCHECK, 0, 0 ) )
  260.         &&
  261.           ( file==1 )
  262.        )
  263.      {
  264.       file=0;
  265.       SendMessage( hX, LB_RESETCONTENT, 0, 0 );
  266.       SendMessage( hY, LB_RESETCONTENT, 0, 0 );
  267.       SendMessage( hZ, LB_RESETCONTENT, 0, 0 );
  268.       lbWidth=0;
  269.       AddXYZLst( hX, (LPSTR) "time" );
  270.       AddXYZLst( hY, (LPSTR) "time" );
  271.       AddXYZLst( hZ, (LPSTR) "time" );
  272.       for( i=0; i<nmetab; i++ )
  273.       {
  274.        wsprintf( (LPSTR) auxstr, "[%s]", (LPSTR) metname[i] );
  275.        AddXYZLst( hX, (LPSTR) auxstr );
  276.        AddXYZLst( hY, (LPSTR) auxstr );
  277.        Add